package com.edu.service.user;

import com.edu.dao.UserDao;
import com.edu.entity.User;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author ZCN
 * @Date 2021/11/11 22:24
 * @Version 1.0
 **/
public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDao();

    // 用户登录方法
    @Override
    public String login(User user) throws SQLException {
        List<User> userList = userDao.login(user);
        if(userList.size() == 0){
            return "用户名或密码错误";
        }
        // 密码不相等
        if(!userList.get(0).getPassword().equals(user.getPassword())){
            return "用户名或密码错误";
        }
        return userList.get(0).getIdent();
    }
    // 用户注册方法
    @Override
    public String register(User user) throws SQLException {
        User userfromdb = userDao.findone(user);
        if(userfromdb != null){
            return "用户名重复，请更换用户名!";
        }
        userDao.register(user);
        return "注册成功，请登录";
    }
}
